home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / hsclib / tag.c < prev    next >
C/C++ Source or Header  |  1996-08-04  |  6KB  |  241 lines

  1. /*
  2.  * tag.c
  3.  *
  4.  * hsc-tag funcs for hsc
  5.  *
  6.  * Copyright (C) 1995,96  Thomas Aglassinger
  7.  *
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  *
  22.  * updated:  4-Aug-1996
  23.  * created:  8-Sep-1995
  24.  */
  25.  
  26. #define NOEXTERN_HSCLIB_TAG_H
  27.  
  28. #include "hsclib/inc_base.h"
  29.  
  30. #include "hsclib/defattr.h"
  31. #include "hsclib/tag.h"
  32.  
  33. /*
  34.  *-------------------------------------
  35.  * constructor/destructor
  36.  *-------------------------------------
  37.  */
  38.  
  39. /*
  40.  * del_hsctag
  41.  */
  42. void del_hsctag(APTR data)
  43. {
  44.     HSCTAG *tag = (HSCTAG *) data;
  45.  
  46.     /* release mem */
  47.     ufreestr(tag->name);
  48.     ufreestr(tag->name);
  49.     del_estr(tag->op_text);
  50.     del_estr(tag->cl_text);
  51.     ufreestr(tag->mbi);
  52.     ufreestr(tag->naw);
  53.     del_dllist(tag->attr);
  54.     del_infilepos(tag->start_fpos);
  55.     del_infilepos(tag->end_fpos);
  56.  
  57.     /* clear values */
  58.     tag->option = 0;
  59.     tag->op_text = NULL;
  60.     tag->cl_text = NULL;
  61.     tag->attr = NULL;
  62.     tag->uri_size = NULL;
  63.     tag->uri_stripext = NULL;
  64.  
  65.     ufree(tag);
  66. }
  67.  
  68. /*
  69.  * new_hsctag
  70.  *
  71.  * alloc & init a new hsctag
  72.  */
  73. HSCTAG *new_hsctag(STRPTR newid)
  74. {
  75.  
  76.     HSCTAG *newtag = (HSCTAG *) umalloc(sizeof(HSCTAG));
  77.  
  78.     if (newtag)
  79.     {
  80.         /* init new tag item */
  81.         newtag->name = upstr(strclone(newid));  /* set id */
  82.         newtag->option = 0;
  83.         newtag->o_handle = NULL;        /* no handle functions */
  84.         newtag->c_handle = NULL;
  85.         newtag->occured = FALSE;
  86.         newtag->op_text = NULL;
  87.         newtag->cl_text = NULL;
  88.         newtag->attr = init_dllist(del_hscattr);
  89.         newtag->mbi = NULL;
  90.         newtag->naw = NULL;
  91.         newtag->uri_size = NULL;
  92.         newtag->uri_stripext = NULL;
  93.         newtag->start_fpos = NULL;
  94.         newtag->end_fpos = NULL;
  95.  
  96.         if (!(newtag->name && newtag->attr))
  97.         {
  98.             del_hsctag(newtag);
  99.             newtag = NULL;
  100.         }
  101.     }
  102.  
  103.     return (newtag);
  104. }
  105.  
  106. /*
  107.  * cpy_hsctag
  108.  *
  109.  * copy an already existing hsctag
  110.  *
  111.  * NOTE: this is not a 100% clone:
  112.  *  - tag-callbacks are disabled and have to be assigned again.
  113.  *  - the occured-flag is disabled
  114.  */
  115. HSCTAG *cpy_hsctag(HSCTAG * oldtag)
  116. {
  117.     HSCTAG *newtag = new_hsctag(oldtag->name);
  118.  
  119.     if (newtag)
  120.     {
  121.         DLNODE *nd = NULL;
  122.  
  123.         /* init new tag item */
  124.         newtag->option = oldtag->option;
  125.         newtag->o_handle = NULL;        /* no handle functions */
  126.         newtag->c_handle = NULL;
  127.         newtag->occured = FALSE;
  128.         newtag->op_text = NULL;
  129.         newtag->cl_text = NULL;
  130.         newtag->attr = init_dllist(del_hscattr);
  131.         newtag->mbi = strclone(oldtag->mbi);
  132.         newtag->naw = strclone(oldtag->naw);
  133.         newtag->uri_size = NULL;
  134.         newtag->uri_stripext = NULL;
  135.  
  136.         /* copy macro text */
  137.         if (oldtag->op_text)
  138.         {
  139.             newtag->op_text = init_estr(0);
  140.             estrcpy(newtag->op_text, oldtag->op_text);
  141.         }
  142.         if (oldtag->cl_text)
  143.         {
  144.             newtag->cl_text = init_estr(0);
  145.             estrcpy(newtag->cl_text, oldtag->cl_text);
  146.         }
  147.  
  148.         /* copy attribute list */
  149.         nd = oldtag->attr->first;
  150.         while (nd)
  151.         {
  152.             HSCATTR *attr = (HSCATTR *) nd->data;       /* old attribute */
  153.  
  154.             /* create copy of old attribute */
  155.             HSCATTR *nattr = cpy_hscattr(attr);
  156.  
  157.             /* append this copy to new attr-list */
  158.             app_dlnode(newtag->attr, nattr);
  159.  
  160.             /* check for special uri-attributes */
  161.             if (!upstrcmp(nattr->name, oldtag->uri_size->name))
  162.                 newtag->uri_size = nattr;
  163.             if (!upstrcmp(nattr->name, oldtag->uri_stripext->name))
  164.                 newtag->uri_size = nattr;
  165.         }
  166.     }
  167.  
  168.     return (newtag);
  169. }
  170.  
  171. /*
  172.  *---------------------------
  173.  * find tag string
  174.  *---------------------------
  175.  */
  176.  
  177. /*
  178.  * cmp_strtag
  179.  *
  180.  * compares a tag-string with the name
  181.  * of a HSCTAG-entry
  182.  */
  183. int cmp_strtag(APTR cmpstr, APTR tagdata)
  184. {
  185.     STRPTR tagstr = NULL;
  186.  
  187.     if (tagdata)
  188.         tagstr = ((HSCTAG *) tagdata)->name;
  189.  
  190.     if (tagstr)
  191.         if (!upstrcmp(cmpstr, tagstr))
  192.             return (-1);
  193.         else
  194.             return (0);
  195.     else
  196.         return (0);
  197. }
  198.  
  199. /*
  200.  * find_strtag
  201.  */
  202. HSCTAG *find_strtag(DLLIST * taglist, STRPTR name)
  203. {
  204.     DLNODE *nd = find_dlnode(taglist->first, (APTR) name, cmp_strtag);
  205.     HSCTAG *tag = NULL;
  206.  
  207.     if (nd)
  208.         tag = (HSCTAG *) nd->data;
  209.  
  210.     return (tag);
  211. }
  212.  
  213. /*
  214.  *-------------------------------------
  215.  * append tag functions
  216.  *-------------------------------------
  217.  */
  218.  
  219. /*
  220.  * app_tag
  221.  *
  222.  * create a new tag and append it to tag-list
  223.  *
  224.  * params: tagid..name of the new tag (eg "IMG")
  225.  * result: ptr to the new tag or NULL if no mem
  226.  */
  227. HSCTAG *app_tag(DLLIST * taglist, STRPTR tagid)
  228. {
  229.     HSCTAG *newtag;
  230.  
  231.     newtag = new_hsctag(tagid);
  232.     if (app_dlnode(taglist, newtag) == NULL)
  233.     {
  234.         del_hsctag((APTR) newtag);
  235.         newtag = NULL;
  236.     }             
  237.  
  238.     return (newtag);
  239. }
  240.  
  241.